"""
FileName：data_template_generator.py
Description：
Author：gaojiahui
Time：2025/8/24 22:45
Website：https://gitee.com/gao-jiahui
"""
from core.data_driver import data_driver
from core.logger import logger


def generate_test_data_templates():
    """生成测试数据模板"""
    templates = [
        {
            "module": "auth",
            "feature": "login",
            "fields": [
                {"name": "test_case_id", "type": "string", "required": True},
                {"name": "description", "type": "string", "required": True},
                {"name": "test_data.username", "type": "string", "required": True},
                {"name": "test_data.password", "type": "string", "required": True},
                {"name": "test_data.captcha", "type": "string", "required": False, "default": "8888"},
                {"name": "expected.status_code", "type": "number", "required": True, "default": 200},
                {"name": "expected.body.access_token", "type": "string", "required": False},
                {"name": "expected.body.token_type", "type": "string", "required": False, "default": "bearer"},
                {"name": "expected.should_succeed", "type": "boolean", "required": True, "default": True}
            ]
        },
        {
            "module": "user",
            "feature": "create",
            "fields": [
                {"name": "test_case_id", "type": "string", "required": True},
                {"name": "description", "type": "string", "required": True},
                {"name": "test_data.username", "type": "string", "required": True},
                {"name": "test_data.phone", "type": "string", "required": True},
                {"name": "test_data.email", "type": "string", "required": True},
                {"name": "test_data.role_ids", "type": "array", "required": True, "default": [1]},
                {"name": "test_data.dept_id", "type": "number", "required": False},
                {"name": "expected.status_code", "type": "number", "required": True, "default": 200},
                {"name": "expected.body.data.userId", "type": "number", "required": False},
                {"name": "expected.should_succeed", "type": "boolean", "required": True, "default": True}
            ]
        },
        {
            "module": "user",
            "feature": "update",
            "fields": [
                {"name": "test_case_id", "type": "string", "required": True},
                {"name": "description", "type": "string", "required": True},
                {"name": "test_data.phone", "type": "string", "required": False},
                {"name": "test_data.email", "type": "string", "required": False},
                {"name": "test_data.role_ids", "type": "array", "required": False, "default": [2]},
                {"name": "expected.status_code", "type": "number", "required": True, "default": 200},
                {"name": "expected.should_succeed", "type": "boolean", "required": True, "default": True}
            ]
        },
        {
            "module": "user",
            "feature": "delete",
            "fields": [
                {"name": "test_case_id", "type": "string", "required": True},
                {"name": "description", "type": "string", "required": True},
                {"name": "expected.status_code", "type": "number", "required": True, "default": 200},
                {"name": "expected.should_succeed", "type": "boolean", "required": True, "default": True}
            ]
        }
    ]

    for template in templates:
        success = data_driver.generate_test_data_template(
            template["module"],
            template["feature"],
            template["fields"]
        )

        if success:
            logger.info(f"成功生成测试数据模板: {template['module']}/{template['feature']}")
        else:
            logger.error(f"生成测试数据模板失败: {template['module']}/{template['feature']}")


if __name__ == "__main__":
    generate_test_data_templates()